package com.BookMate.mapper;
import com.BookMate.domain.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

public interface UserMapper{
    @Select("select * from user where user_email=#{email} AND user_password=#{password} AND user_status!='1'")
    @Results(id = "userMap",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "user_id",property = "id"),
            @Result(column = "user_name",property = "name"),
            @Result(column = "user_password",property = "password"),
            @Result(column = "user_email",property = "email"),
            @Result(column = "user_role",property = "role"),
            @Result(column = "user_status",property = "status")
    })
    User login(User user);
    Integer addUser(User user);

    @Select({"<script>" +
            "SELECT * FROM user " +
            "where 1=1" +
            "<if test=\"name != null\"> AND  user_name  like  CONCAT('%',#{name},'%')</if>" +
            "<if test=\"email != null\"> AND user_email like  CONCAT('%', #{email},'%') </if>" +
            "<if test=\"status != null\"> AND user_status like  CONCAT('%', #{status},'%')</if>" +
            "order by user_id" +
            "</script>"
    })
    @ResultMap("userMap")
        //分页查询用户
    Page<User> searchUsers(User user);
    @Select("SELECT * FROM user where user_id=#{id}")
    @ResultMap("userMap")
//根据id查询用户信息
    User findById(String id);
    Integer editUser(User user);
    @Delete("delete from user where user_id = #{userId}")
    @ResultMap("userMap")
    boolean deleteUser(String id);
}
